package com.example.demo.config;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;

@RestControllerAdvice   // 当前是针对 controller 的通知类
public class MyExceptionAdvice {

    @ExceptionHandler(Exception.class)
    public Object handler(Exception e) {
        HashMap<String,Object> map = new HashMap<>();
        map.put("state",0);
        map.put("data",null);
        map.put("msg","错误信息是"+e.getMessage());
        return map;
    }
}
